package org.example.RobotModel.serializer;

import com.google.inject.Inject;
import com.google.inject.Provider;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.serializer.acceptor.ISemanticSequenceAcceptor;
import org.eclipse.xtext.serializer.acceptor.SequenceFeeder;
import org.eclipse.xtext.serializer.diagnostic.ISemanticSequencerDiagnosticProvider;
import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor;
import org.eclipse.xtext.serializer.sequencer.AbstractDelegatingSemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.GenericSequencer;
import org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider;
import org.eclipse.xtext.serializer.sequencer.ISemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.ITransientValueService;
import org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient;
import org.example.RobotModel.robotDsl.Action;
import org.example.RobotModel.robotDsl.Activator;
import org.example.RobotModel.robotDsl.Param;
import org.example.RobotModel.robotDsl.Retour;
import org.example.RobotModel.robotDsl.Robot;
import org.example.RobotModel.robotDsl.RobotDslPackage;
import org.example.RobotModel.robotDsl.Sensor;
import org.example.RobotModel.services.RobotDslGrammarAccess;

@SuppressWarnings("all")
public class RobotDslSemanticSequencer extends AbstractDelegatingSemanticSequencer {

	@Inject
	private RobotDslGrammarAccess grammarAccess;
	
	public void createSequence(EObject context, EObject semanticObject) {
		if(semanticObject.eClass().getEPackage() == RobotDslPackage.eINSTANCE) switch(semanticObject.eClass().getClassifierID()) {
			case RobotDslPackage.ACTION:
				if(context == grammarAccess.getActionRule()) {
					sequence_Action(context, (Action) semanticObject); 
					return; 
				}
				else break;
			case RobotDslPackage.ACTIVATOR:
				if(context == grammarAccess.getActivatorRule() ||
				   context == grammarAccess.getDeviceRule()) {
					sequence_Activator(context, (Activator) semanticObject); 
					return; 
				}
				else break;
			case RobotDslPackage.PARAM:
				if(context == grammarAccess.getParamRule()) {
					sequence_Param(context, (Param) semanticObject); 
					return; 
				}
				else break;
			case RobotDslPackage.RETOUR:
				if(context == grammarAccess.getRetourRule()) {
					sequence_Retour(context, (Retour) semanticObject); 
					return; 
				}
				else break;
			case RobotDslPackage.ROBOT:
				if(context == grammarAccess.getRobotRule()) {
					sequence_Robot(context, (Robot) semanticObject); 
					return; 
				}
				else break;
			case RobotDslPackage.SENSOR:
				if(context == grammarAccess.getDeviceRule() ||
				   context == grammarAccess.getSensorRule()) {
					sequence_Sensor(context, (Sensor) semanticObject); 
					return; 
				}
				else break;
			case RobotDslPackage.SYSTEM:
				if(context == grammarAccess.getSystemRule()) {
					sequence_System(context, (org.example.RobotModel.robotDsl.System) semanticObject); 
					return; 
				}
				else break;
			}
		if (errorAcceptor != null) errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
	}
	
	/**
	 * Constraint:
	 *     (name=ID params+=Param* retour=Retour?)
	 */
	protected void sequence_Action(EObject context, Action semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (name=ID actions+=Action+)
	 */
	protected void sequence_Activator(EObject context, Activator semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (name=ID type=Type)
	 */
	protected void sequence_Param(EObject context, Param semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, RobotDslPackage.Literals.PARAM__NAME) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, RobotDslPackage.Literals.PARAM__NAME));
			if(transientValues.isValueTransient(semanticObject, RobotDslPackage.Literals.PARAM__TYPE) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, RobotDslPackage.Literals.PARAM__TYPE));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getParamAccess().getNameIDTerminalRuleCall_0_0(), semanticObject.getName());
		feeder.accept(grammarAccess.getParamAccess().getTypeTypeParserRuleCall_2_0(), semanticObject.getType());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     type=Type
	 */
	protected void sequence_Retour(EObject context, Retour semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, RobotDslPackage.Literals.RETOUR__TYPE) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, RobotDslPackage.Literals.RETOUR__TYPE));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getRetourAccess().getTypeTypeParserRuleCall_1_0(), semanticObject.getType());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     (name=ID devices+=[Device|ID]+)
	 */
	protected void sequence_Robot(EObject context, Robot semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (name=ID actions+=Action+)
	 */
	protected void sequence_Sensor(EObject context, Sensor semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (devices+=Device* robot=Robot)
	 */
	protected void sequence_System(EObject context, org.example.RobotModel.robotDsl.System semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
}
